(function() {
	var controller = null;
	var view = null;

	module('PadLock Tests', {
		setup : function() {
			controller = null;
			view = null;
		}

	});

	test('Start of game', function() {
		initControllerWithConf(createLockValuesFromConf('XXX OOO'));

		controller.show();

		ok(view.initCalled == true);
		deepEqual(view.data, createLockValuesFromConf('XXX OOO'));
	});

	test('Click on element', function() {
		initControllerWithConf(createLockValuesFromConf('XXX OOO'));

		controller.onMove(2);

		deepEqual(view.data, createLockValuesFromConf('XX XOOO'));
	});

	test('Click on element, no move', function() {
		initControllerWithConf(createLockValuesFromConf('XXX OOO'));

		controller.onMove(5);

		deepEqual(view.data, createLockValuesFromConf('XXX OOO'));
	});

	test('Click on no element', function() {
		initControllerWithConf(createLockValuesFromConf('XXX OOO'));

		controller.onMove(3);

		deepEqual(view.data, createLockValuesFromConf('XXX OOO'));
	});

	test('Click on element, win', function() {
		initControllerWithConf(createLockValuesFromConf('OOOX XX'));

		controller.onMove(3);

		ok(view.onSolvedCalled == true);
	});

	test('Click on reset', function() {
		initControllerWithConf(createLockValuesFromConf('OOOX XX'));

		controller.onReset();

		ok(view.resetCalled == true);
		deepEqual(view.data, createLockValuesFromConf('XXX OOO'));
	});

	function TestView() {
		this.onSolvedCalled = false;
		this.resetCalled = false;
		this.initCalled = false;
	}

	TestView.prototype.onSolved = function() {
		this.onSolvedCalled = true;
	};

	TestView.prototype.refresh = function(data) {
		this.data = data;
	};

	TestView.prototype.init = function() {
		this.initCalled = true;
	};

	TestView.prototype.reset = function() {
		this.resetCalled = true;
	};

	function initControllerWithConf(conf) {
		view = new TestView();
		controller = new PadlockController(view, conf);
	}
}());